#ifndef ITEM_H
#define ITEM_H



#include "XmlDefines.h"
#include "d20Model_global.h"



#include <QString>
#include <QVariant>

#include <QDomElement>

#include <QSharedData>
#include <QSharedDataPointer>



static quint16 ID(QString name, int type)
{
    QString str = QString("%1%2").arg(name).arg(type);
    quint16 crc = qChecksum(str.toAscii(), str.toAscii().length());
    return crc;
}


class D20_MODELSHARED_EXPORT Item : public QObject
{
    class Data : public QSharedData
    {
    public:
        Data() {}
        Data(const Data& other) : QSharedData(other)
        {
            id = other.id;
            name = other.name;
            value = other.value;
            desc = other.desc;
            type = other.type;
        }

        QVariant id;

        QString name;
        QVariant value;

        QString desc;
        QVariant type;
    };

    Q_OBJECT

public:


    Item(const QString& name, const QVariant& type, QObject* parent = 0);
    Item(const QVariant& type, QObject* parent = 0);
    Item(const Item& other);

    virtual QVariant id() const;
    virtual void regenId();

    virtual QString name() const;
    virtual void setName(const QString& name);

    virtual QVariant value() const;
    virtual void setValue(const QVariant& value);

    virtual QString desc() const;
    virtual void setDesc(const QString& text);

    virtual QVariant type() const;
    virtual void setType(const QVariant& type);


    virtual QDomElement toXmlElem(QDomElement& elem) const;
    virtual void fromXmlElem(QDomElement& elem);

    virtual QVariant bonus() = 0;


signals:

    void sigChanged();
    void sigRegenId(const QVariant& old_id);


private:

    QSharedDataPointer<Data> data;


};


#endif // ITEM_H


